package com.base.library.utils

import com.google.gson.Gson
import java.io.Reader
import java.lang.reflect.Type
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class GsonUtils @Inject constructor(private val gson: Gson) {

    fun toJson(data: Any?): String {
        return gson.toJson(data)
    }

    fun <T> fromJson(json: String?, type: Class<T>): T? {
        return gson.fromJson(json, type);
    }

    fun <T> fromJson(json: String?, type: Type): T? {
        return gson.fromJson(json, type)
    }

    fun <T> fromJson(value: Reader, clazz: Class<T>?): T? {
        return gson.fromJson(value, clazz)
    }

    fun <T> fromJson(value: Reader, clazz: Type?): T? {
        return gson.fromJson(value, clazz)
    }
}